package hah;

import sun.util.resources.cldr.zh.CalendarData_zh_Hans_HK;

import java.util.Iterator;
import java.util.LinkedList;

class MyHashSet {
    private int base=769;
    private LinkedList[] data;

    /** Initialize your data structure here. */
    public MyHashSet() {
            data=new LinkedList[base];
            for (int i=0;i<base;i++){
                data[i]=new LinkedList();
            }
    }

    public void add(int key) {
        int index=Hash(key);
        Iterator<Integer> iterator = data[index].iterator();
        while (iterator.hasNext()){
            Integer next = iterator.next();
            if (next==key){
                return;
            }
        }
        data[index].offerLast(key);
    }

    public void remove(int key) {
        int index=Hash(key);
        Iterator<Integer> iterator = data[index].iterator();
        while (iterator.hasNext()){
            Integer next=iterator.next();
            if (next==key)
                data[index].remove(next);
                return;
        }
    }

    /** Returns true if this set contains the specified element */
    public boolean contains(int key) {
        int index=Hash(key);
        Iterator<Integer> iterator = data[index].iterator();
        while (iterator.hasNext()){
            Integer next=iterator.next();
            if (next==key)
                return true;
        }
        return false;
    }
    public int Hash(int val){
        return val%base;
    }

}
